package com.demo.service.impl;

import com.demo.dao.ProductDao;
import com.demo.dao.User2Dao;
import com.demo.dao.UserDao;
import com.demo.model.Product;
import com.demo.model.User2;
import com.demo.service.ProductService;
import com.demo.service.User2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class User2ServiceImpl implements User2Service {
    @Autowired
    private User2Dao user2Dao;

    @Override
    public int save(User2 user2) {
        return user2Dao.insert(user2);
    }

    @Override
    public User2 getUser2ById(Integer id) {
        return user2Dao.selectOne(id);
    }

    @Override
    public Integer updateUser2(User2 user2) {
        if (user2.getId() != null && user2.getId() > 0) {
            return user2Dao.update(user2);
        }
        return user2Dao.insert(user2);
    }

    @Override
    public Integer deleteUser2(int id) {
        return user2Dao.delete(id);
    }

    @Override
    public List<User2> getUser2s(String username) {
        return user2Dao.select(username);
    }
}
